//
//  ZYCProtalNoticePushDeptCell.m
//  ZDSC
//
//  Created by ZDTX on 2021/8/18.
//

#import "ZYCProtalNoticePushDeptCell.h"
#import "ZYCRoleTreeModel.h"
#import "UIButton+EnlargeEdge.h"
@interface ZYCProtalNoticePushDeptCell ()

@property (nonatomic, strong) UIButton *selectButton;
@property (nonatomic, strong) UIImageView *iconImageView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *contentLabel;
@property (nonatomic, strong) UIImageView *arrowImageView;
@property (nonatomic, strong) UILabel *line;

@end
@implementation ZYCProtalNoticePushDeptCell

- (void)setModel:(ZYCRoleTreeModel *)model{
    _model = model;
    _titleLabel.text = model.label;
    _selectButton.selected = model.isSelected;
    _contentLabel.text = [NSString stringWithFormat:@"已选%@人",@(model.selectedCnt).stringValue];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.selectButton];
        [self.contentView addSubview:self.iconImageView];
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.contentLabel];
        [self.contentView addSubview:self.arrowImageView];
        [self.contentView addSubview:self.line];

        [self.selectButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(15.0f);
            make.centerY.equalTo(self.contentView);
            make.size.mas_equalTo(CGSizeMake(13, 13));
        }];

        [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.selectButton.mas_right).offset(16.0f);
            make.centerY.equalTo(self.contentView);
            make.size.mas_equalTo(CGSizeMake(14.5, 14.5));
        }];
        
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.iconImageView.mas_right).offset(5.0f);
            make.centerY.equalTo(self.contentView);
        }];
        
        [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.arrowImageView.mas_left).offset(-18.0f);
            make.centerY.equalTo(self.contentView);
        }];
        
        [self.arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView).offset(-24.0f);
            make.centerY.equalTo(self.contentView);
            make.size.mas_equalTo(CGSizeMake(7, 12));
        }];
        
        [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(15.0f);
            make.right.equalTo(self.contentView).offset(-15.0f);
            make.bottom.equalTo(self.contentView);
            make.height.mas_equalTo(0.5);
        }];
        
    }
    return self;
}

- (UIButton *)selectButton {
    if (!_selectButton) {
        _selectButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_selectButton addTarget:self action:@selector(clickSelectAction:) forControlEvents:UIControlEventTouchUpInside];
        [_selectButton setImage:[UIImage imageNamed:@"xzz"] forState:UIControlStateNormal];
        [_selectButton setImage:[UIImage imageNamed:@"fxz"] forState:UIControlStateSelected];
        [_selectButton setEnlargeEdgeWithTop:20 right:20 bottom:20 left:20];
    }
    return _selectButton;
}

- (UIImageView *)arrowImageView {
    if (!_arrowImageView) {
        _arrowImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"jt"]];
    }
    return _arrowImageView;
}


- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Regular", 18) titleColor:HEX_RGB(@"333333") textAlignment:ZZTextAlignmentLeft];
    }
    return _titleLabel;
}

- (UILabel *)contentLabel {
    if (!_contentLabel) {
        _contentLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Regular", 16) titleColor:HEX_RGB(@"#999999") textAlignment:ZZTextAlignmentLeft];
    }
    return _contentLabel;
}

- (UIImageView *)iconImageView {
    if (!_iconImageView) {
        _iconImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bm"]];
    }
    return _iconImageView;
}

- (UILabel *)line {
    if (!_line) {
        _line = [[UILabel alloc] init];
        _line.backgroundColor = HEX_RGB(@"#DEDEDE");
    }
    return _line;
}


- (void)clickSelectAction:(UIButton *)sender{
    self.model.isSelected = !sender.selected;
    sender.selected = self.model.isSelected;
    !self.selectAction ?: self.selectAction(self.model.isSelected);
}

@end
